# Ղ̌
# ============================================================================
#	@CNt@C
# ============================================================================
include	/sys/sys.mak
TARGET	=	main
# ============================================================================
#	Ώۃt@C
# ============================================================================
include	files.mak
# ============================================================================
#	ŏI^[Qbg
# ============================================================================
all:	mentry write

write:	${TARGET}.bin
	${expand ${HDW} -U${PROGSIZE},$${CDPOS_${TARGET}} $^ ${PROGNAME}}
	${expand ${cdlen}}
	gmake -c \ipl

${TARGET}.bin:	${FILES} linkfile
	lk -b$@ -m${TARGET}.map -s${TARGET}.sym @linkfile

clean:
	${cmdsplit -rm %,60,${FILES}}
	-rm ${TARGET}.bin

linkfile:	${TARGET}.lnk files.mak
	techo -i ${TARGET}.lnk
	${cmdsplit techo %,60,${FILES}}
	techo -o $@
# ----------------------------------------------------------------------------
#	Iȃ[
# ----------------------------------------------------------------------------
mainwork.o:	mainwork.pub mainwork.ext

mainwork.pub:	mainwork.s
	sed -n "s/^\([A-Za-z_][0-9A-Za-z_]*\).*$$/\tpublic\t\1/p" $^ >$@
mainwork.ext:	workext.sed mainwork.s
	sed -f $^ >$@
# ---------------------------------------------------------------------------
mentry:	mentry.pub mentry.equ mentry.ext

mentry.pub:	mentry.s
	sed -n s/^\tjmp_\t\([A-Za-z_][0-9A-Za-z_]*\).*$$/\tpublic\t\1/p $^>$@
mentry.ext:	mentry.s
	sed -n s/^\tjmp_\t\([A-Za-z_][0-9A-Za-z_]*\).*$$/\textrn\t\1/p $^>$@
mentry.equ:	entequ.awk mentry.s
	jgawk -vtop="3800" -f $^ >$@
# ---------------------------------------------------------------------------
init.s:	ar_init.s
	sed "s/^[ \t]*seg[ \t]*cseg/\tdefseg\tinit\n\tseg\tinit/" $^ >$@
